/**
 * Sample React Native App By Wyh
 * Created by wyh on 15/12/23.
 */
'use strict';

import React ,{
  StyleSheet,
  View,
  AsyncStorage,
} from 'react-native';

//引导页
import Guide from './guide';

//路由
import Route from './route';


const App = React.createClass({


  /**
   * 初始化状态
   */
  getInitialState(){
    return ({
      //是否显示引导页
      showGuide: false
    });
  },


  componentDidMount(){
    AsyncStorage.getItem('rn_wyh@showGuide', (err, data) => {
      console.log('rn_wyh@showGuid=====' + data);
      if(!data){
        this.setState({
          showGuide: true
        });
      }
    });
  },


  render() {
    if (this.state.showGuide) {
      return (
        <Guide onPress={this._loginIn}/>
      );
    }
    return (
      <View style={styles.container}>
        <Route/>
      </View>
    );
  },


  _loginIn() {
    AsyncStorage.setItem('rn_wyh@showGuide', '1');
    this.setState({
      showGuide: false
    });
  },

});


const styles = StyleSheet.create({
  container: {
    flex: 1
  },
});


module.exports = App;